<?php
class FinanceMonthAction extends AppAction {
	private $lib;
	private $adminGrand;
	function __construct() {
		parent::__construct ();
		require_once APP_LIB_PATH . 'financeMonthLib.php';
		$this->lib = new FinanceMonthLib ();
		$this->adminGrand = AdminSession::getAdminSessionInfo ();
		AdminVisitor::checkGrant ( 'finance' );
	}
	public function monthlist() {
		$this->lib->getMonthList ();
		BaseAction::loadView ( 'admin/FinanceMonthList' );
	}
	public function monthexportexcel() {
		if (isset ( $_POST ['FinanceId'] ) && isset ( $_GET ['menu'] )) {
			if ($_GET ['menu'] == 'exportExcel') {
				$this->lib->exportExcel ( $_POST ['FinanceId'] );
			}
		} else {
			BaseAction::adminError ( "请不要非法操作" );
		}
	}
	public function monthadd() {
		ViewData::$form_data = new FinanceMonthClass ();
		ViewData::$form_hint = new FinanceMonthClass ();
		if ($_POST) {
			$this->lib->addMonthForm ();
			if (! $this->lib->addMonthLogic ()) {
				ViewData::$form_hint->Message = "添加失败，请检查数据的合法性";
			} else {
				Header ( "Location:  " . siteUrl ( 'Financemonth/monthlist' ) . "" );
			}
		}
		BaseAction::loadView ( 'admin/financeMonthAdd' );
	}
	
	public function monthdel() {
		if (! isset ( $_GET ['FinanceId'] )) {
			BaseAction::adminError ( "请不要非法操作" );
		}
		if (! $this->lib->delMonthInfo ( $_GET ['FinanceId'] )) {
			BaseAction::adminError ( "删除失败" );
		}
		BaseAction::adminSuccess ( "删除成功", siteUrl ( 'financemonth/monthlist' ) );
	}
	
	public function monthedit() {
		if (! isset ( $_GET ['FinanceId'] )) {
			BaseAction::adminError ( "请不要非法操作" );
		}
		ViewData::$form_hint = new FinanceMonthClass ();
		ViewData::$form_data = $this->lib->getMonthInfoByFinanceId ( $_GET ['FinanceId'] );
		if ($_POST) {
			$this->lib->addMonthForm ();
			if (! BaseAction::isObjectEmpty ( ViewData::$form_hint )) {
				BaseAction::loadView ( "admin/financeMonthAdd" );
			}
			try {
				$this->lib->setMonthInfo ();
				Header ( "Location:  " . siteUrl ( 'Financemonth/monthlist' ) . "" );
			} catch ( Exception $e ) {
				ViewData::$form_hint->Message = $e->getMessage ();
			}
		}
		BaseAction::loadView ( "admin/financeMonthAdd" );
	}
	
	public function delCheck() {
		if (isset ( $_POST ['FinanceId'] ) && isset ( $_GET ['menu'] )) {
			if ($_GET ['menu'] == 'delCheck') {
				foreach ( $_POST ['FinanceId'] as $value ) {
					$this->lib->delMonthInfo ( $value );
				}
				BaseAction::adminSuccess ( "删除成功", siteUrl ( 'Financemonth/monthlist' ) );
				exit ();
			} else {
				BaseAction::adminError ( "请不要非法操作" );
			}
		}
	}
}